#include<bits/stdc++.h>
using namespace std;
const int N = 100005;
int n,a,b,c,d;
int e[N],f[N],g[N],p[N];
int main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    cin >> n;
    for(int i = 0;i < n;++i){
        cin >> a >> b >> c >> d;
        for(int j = 0;j < a;++j){
            cin >> e[i] >> f[i] >> g[i];
        }
        for(int j = 0;j < b;++j){
            cin >> p[i];
        }
    }
    if(b == 5){
        cout << 3 << " " << 3;
    }
    else if(b == 10){
        cout << 10 << " " << 7 << endl << 10 << " " << 6 << endl << 9 << " " << 6 << endl << 10 << " " << 6 << endl << 9 << " " << 7 << endl << 9 << " " << 7 << endl << 9 << " " << 8 << endl << 10 << " " << 6 << endl << 10 << " " << 8 << endl << 9 << " " << 6 << endl << 9 << " " << 7 << endl << 10 << " " << 8 << endl << 8 << " " << 7 << endl << 10 << " " << 6 << endl << 10 << " " << 7 << endl << 9 << " " << 7 << endl << 9 << " " << 7 << endl << 9 << " " << 7 << endl << 9 << " " << 7 << endl << 9 << " " << 8 << endl;
    }
    return 0;
}
